package com.hspedu.newData.dmsxl.滑动窗口;

import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-29 
 * @Version: 1.0
 */

public class LC2962统计最大元素出现至少k次的子数组 {

    public long countSubarrays(int[] nums, int k) {

        int len = nums.length;
        int max = 0;
        for (int i = 0; i < len; i++) {
            if (nums[i] > max){
                max = nums[i];
            }
        }
        long res = 0;
        int count = 0;
        int slow = 0;
        for (int i = 0; i < len; i++) {
            if (nums[i] == max){
                count++;
                while (count == k){
                    res += len - i;
                    if (nums[slow++] == max){
                        count--;
                    }
                }
            }
        }
        return res;



    }

    @Test
    public void test() {
        // 测试代码

        countSubarrays(new int[]{1,4,2,1},3);
        System.out.println("-");
    }

}
